package com.iot.modbus.factory.impl;


import com.iot.modbus.factory.ReaderSessionFactory;
import com.iot.modbus.factory.SessionFactory;
import com.iot.modbus.reader.ReaderSession;
import com.iot.modbus.reader.impl.SimpleReaderSession;
import com.serotonin.modbus4j.exception.ModbusIdException;
import com.serotonin.modbus4j.exception.ModbusTransportException;
import com.serotonin.modbus4j.ip.IpParameters;
import com.serotonin.modbus4j.msg.ModbusRequest;

import static com.iot.modbus.factory.SessionFactory.modbusFactory;

public class SimpleReaderSessionFactory  implements ReaderSessionFactory {

    @Override
    public ReaderSession createReaderSession(IpParameters ipParameters) {
        return new SimpleReaderSession(SessionFactory.get(ipParameters));
    }

    public ModbusRequest createReadRequest(int slaveId, int range, int offset, int length) throws ModbusTransportException, ModbusIdException{
        return modbusFactory.createReadRequest(slaveId, range, offset, length);
    }

}
